#include <adc.h>
#include "DioLib.h"
#include "AdcLib.h"

void ADC1_init(void)
{
	// ADC configuration.
	AdcRng(pADI_ADC1, ADCCON_ADCREF_INTREF, ADCMDE_PGA_G1, ADCCON_ADCCODE_INT);
	AdcFlt(pADI_ADC1, 19, 0, 0);
    
	AdcMski(pADI_ADC1, ADCMSKI_RDY, 1); 
    AdcBuf(pADI_ADC1,ADCCFG_EXTBUF_OFF,ADCCON_BUFBYPN|ADCCON_BUFBYPP|ADCCON_BUFPOWP|ADCCON_BUFPOWN); 
    AdcGo(pADI_ADC1, ADCMDE_ADCMD_IDLE);
    NVIC_EnableIRQ(ADC1_IRQn);
}

void HS_start_continuous(void)
{
	AdcGo(pADI_ADC1, ADCMDE_ADCMD_IDLE);
	if ((pADI_ADC1->MDE & ADCMDE_ADCMD_MSK) != ADCMDE_ADCMD_CONT){
		pADI_ADC1->CON &= ~(uint32_t)ADCCON_ADCREF_MSK;
		pADI_ADC1->CON |= ADCCON_ADCREF_EXTREF;
		AdcPin(pADI_ADC1, ADCCON_ADCCN_AGND, ADCCON_ADCCP_AIN2);
		AdcGo(pADI_ADC1, ADCMDE_ADCMD_CONT);
	}
}
